#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 8010, M = 310;

int n, m;
int p[M];

struct Edge{
    int a, b, w;
    bool operator< (const Edge & W) const{
        return w < W.w;
    }
}edge[N];

int find(int x){
    if(x != p[x]){
        p[x] = find(p[x]);
    }

    return p[x];
}

bool kruskal(int border){
    int cnt = 0;
    for(int i = 0; i < m; i ++){
        int x = edge[i].a;
        int y = edge[i].b;
        int z = edge[i].w;

        if(z > border) break;
        int a = find(x), b = find(y);
        if(a != b){
            p[a] = p[b];
            cnt ++;
        }
    }

    if(cnt == n - 1){
        return true;
    }else{
        return false;
    }
}

void init(){
    for(int i = 1; i <= n; i ++){
        p[i] = i;
    }
}


bool check(int border){
    init();

    return kruskal(border);
}

int solve(){
    int l = 1, r = 10000;
    while(l < r){
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        }else{
            l = mid + 1;
        }
    }

    return l;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i ++){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        edge[i].a = x;
        edge[i].b = y;
        edge[i].w = z;
    }

    sort(edge, edge + m);

    int t = solve();
    printf("%d %d", n - 1, t);
    return 0;
}